package com.keensense.vcm.internal;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import com.keensense.vcm.HttpMethod;
import com.keensense.vcm.common.auth.CredentialsProvider;
import com.keensense.vcm.common.comm.RequestMessage;
import com.keensense.vcm.common.comm.ServiceClient;
import com.keensense.vcm.common.parser.ResponseParsers;
import com.keensense.vcm.model.SearchSuspectTaskRequest;
import com.keensense.vcm.model.SearchSuspectTaskResponse;

/**
 * @author lanjian
 * @date 2020/5/28 4:52 下午
 */
public class SuspectOperation extends VCMOperation {

    public SuspectOperation(ServiceClient client, CredentialsProvider credsProvider) {
        super(client, credsProvider);
    }

    /**
     * 1、查询布控任务。
     * <P>
     * 2、VCM北向接口请求中可能新增可选字段，或响应中增加字段。 ISV客户端需支持过滤不使用的新增字段，进行兼容性处理。
     * </p>
     * 
     * @param searchSuspectTaskRequest
     * @return
     */
    public SearchSuspectTaskResponse searchSuspectTask(SearchSuspectTaskRequest searchSuspectTaskRequest) {
        String xml = getXmlFromObject(searchSuspectTaskRequest, SearchSuspectTaskRequest.class);
        InputStream in = new ByteArrayInputStream(xml.getBytes());
        RequestMessage request = new VCMRequestMessageBuilder(getInnerClient()).setInputStream(in)
            .setInputSize(xml.getBytes().length).setEndpoint(endpoint).setMethod(HttpMethod.POST).build();
        request.setResourcePath(VCMResourcePathConstants.SEARCH_SUSPECT_TASK);
        SearchSuspectTaskResponse result = doOperation(request, ResponseParsers.searchSuspectResponseParser, true);
        return result;
    }
}
